<ul id="directory_tree" class="directories ztree"></ul>
<script language="javascript" type="text/javascript">
<?php
$script = "var nodes=[{name:'".$this->rootName."', click:\"showFiles('".$this->rootPath."')\", open:true,";
function renderDirectoryTree(array $dirs, &$script) {
    foreach ($dirs as $dir):
        $script .= "{name:'".$dir['name']."', click:\"showFiles('".str_replace(DS, '/', str_replace(BP, '', $dir['path']))."')\"";
        if (!empty($dir['subDirectories'])):
            $script .= ',open:true,nodes:[';
            renderDirectoryTree($dir['subDirectories'], $script);
            $script = substr($script, 0, -1).']';
        endif;
        $script .= '},';
    endforeach;
}
if(count($this->directories) > 0){
    $script .= 'nodes:[';
    renderDirectoryTree($this->directories, $script);
    $script = substr($script, 0, -1).']';

}else{
    $script = substr($script, 0, -1);
}
$script .= '}];';
echo $script;
?>
$('#directory_tree').zTree({showLine:false}, nodes);
</script>